/*
 * @创建文件时间: 2021-06-03 00:50:28
 * @Auther: 猿小天
 * @最后修改人: 猿小天
 * @最后修改时间: 2021-11-29 10:46:51
 * 联系Qq:1638245306
 * @文件介绍: 菜单的按钮和接口配置
 */
import { BUTTON_WHETHER_BOOL } from '@/config/button'
import { request } from '@/api/service'
export const crudOptions = (vm) => {
  return {
    pageOptions: {
      compact: true
    },
    options: {
      tableType: 'vxe-table',
      rowKey: true, // 必须设置，true or false
      rowId: 'id',
      height: '100%', // 表格高度100%, 使用toolbar必须设置
      highlightCurrentRow: false,
      treeConfig: { // 树形数据配置
        children: 'children',
        hasChild: 'hasChildren',
        expandAll: true
      }
    },
    rowHandle: {
      width: 140,
      view: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Retrieve')
        }
      },
      edit: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Update')
        }
      },
      remove: {
        thin: true,
        text: '',
        disabled () {
          return !vm.hasPermissions('Delete')
        }
      }
    },
    indexRow: { // 或者直接传true,不显示title，不居中
      title: '序号',
      align: 'center',
      width: 100
    },
    viewOptions: {
      componentType: 'form'
    },
    formOptions: {
      defaultSpan: 24, // 默认的表单 span
      width: '35%'
    },
    columns: [{
      title: '关键词',
      key: 'search',
      show: false,
      disabled: true,
      search: {
        disabled: false
      },
      form: {
        disabled: true
      },
      view: { // 查看对话框组件的单独配置
        disabled: true
      }
    },
    {
      title: 'ID',
      key: 'id',
      show: false,
      width: 90,
      form: {
        disabled: true
      }
    },
    {
      title: '项目',
      key: 'project',
      show: true,
      search: {
        disabled: true
      },
      type: 'select',
      dict: {
        cache: true,
        url: '/api/config/project/?limit=999',
        value: 'id', // 数据字典中value字段的属性名
        label: 'name', // 数据字典中label字段的属性名
        getData: (url) => { // 配置此参数会覆盖全局的getRemoteDictFunc
          return request({ url: url }).then(ret => {
            return ret.data.data
          })
        }
      },
      form: {
        component: {
          name: 'dict-select',
          props: {
            elProps: {
              clearable: true,
              showAllLevels: false, // 仅显示最后一级
              props: {
                checkStrictly: true, // 可以不需要选到最后一级
                emitPath: false,
                clearable: true
              }
            }
          }
        }
      }
    },
    {
      title: '模块名称',
      key: 'name',
      search: {
        disabled: false
      },
      type: 'input',
      show: true,
      form: {
        rules: [ // 表单校验规则
          { required: true, message: '必填项' }
        ],
        component: {
          span: 24,
          placeholder: '请输入更新标题'
        },

        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '备注',
      key: 'description',
      search: {
        disabled: true
      },
      type: 'textarea',
      show: false,
      form: {
        rules: [ // 表单校验规则
          { max: 1000, message: '最大输入1000，请重新输入', trigger: 'blur' },
          { required: true, message: '必填项' }
        ],
        component: {
          span: 24,
          placeholder: '备注',
          showWordLimit: true,
          props: {
            type: 'textarea',
            autosize: {
              minRows: 2, maxRows: 8
            }
          }
        },

        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '版本号',
      key: 'version',
      search: {
        disabled: false
      },
      type: 'input',
      form: {
        rules: [ // 表单校验规则
          { required: true, message: '必填项' },
          { pattern: /^([0-9]\d|[0-9])(\.([0-9]\d|\d)){2}$/, message: '请输入正确的版本号' }
        ],
        component: {
          span: 24,
          placeholder: '请输入版本号'

        },

        itemProps: {
          class: { yxtInput: true }
        },
        helper: '版本号请以x.x.x的形式'
      }
    },
    {
      title: '包地址',
      key: 'file_url',
      search: {
        disabled: true
      },
      type: 'input',
      show: false,
      form: {
        disabled: true,
        rules: [ // 表单校验规则
          { required: true, message: '必填项' }
        ],
        component: {
          span: 24,
          placeholder: '请输入包地址'
        },

        itemProps: {
          class: { yxtInput: true }
        }
      }
    },
    {
      title: '启用',
      key: 'enable',
      type: 'dict-switch',
      show: false,
      search: {
        disabled: true
      },
      dict: {
        data: BUTTON_WHETHER_BOOL
      },
      form: {
        value: false,
        component: {

        }
      }
    },
    {
      title: '上线发行',
      key: 'status',
      search: {
        disabled: true
      },
      type: 'dict-switch',
      dict: {
        data: [
          {
            label: '上线',
            value: true,
            color: 'success'
          },
          {
            label: '下线',
            value: false,
            color: 'danger'
          }
        ]
      },
      form: {
        value: true,
        component: {
          placeholder: '请选择上线发行'
        }
      }
    }
    ]
  }
}
